package com.example.jn_dxs.Ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Toast;

import com.alibaba.fastjson.JSONObject;
import com.example.jn_dxs.Base.BaseActivity;
import com.example.jn_dxs.Base.BaseViewModel;
import com.example.jn_dxs.R;
import com.example.jn_dxs.Ui.MainActivity;
import com.example.jn_dxs.ViewModel.LoginVM;
import com.example.jn_dxs.databinding.ActivityLoginBinding;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;

public class LoginActivity extends BaseActivity<LoginVM, ActivityLoginBinding> {



    @Override
    protected int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected void initEventAndView() {

    }

    @Override
    protected void statusBar() {
        super.statusBar();

        ImmersionBar
                .with(this)
                .reset()
                .statusBarColor(R.color.white)
                .statusBarDarkFont(true)
                .fitsSystemWindows(true)
                .keyboardEnable(true)
                .hideBar(BarHide.FLAG_HIDE_STATUS_BAR)
//                .navigationBarColor(R.color.hl_white)
//                .navigationBarDarkIcon(true)
                .init();

    }

    @Override
    public void initClick() {
        binding.btnLogin.setOnClickListener(v -> {
            if (binding.name.getText().toString().isEmpty()) {
                Toast.makeText(this, "请输入账号", Toast.LENGTH_SHORT).show();
                return;
            }
            if (binding.password.getText().toString().isEmpty()) {
                Toast.makeText(this, "请输入密码", Toast.LENGTH_SHORT).show();
                return;
            }
            model.getLogin(binding.name.getText().toString(),binding.password.getText().toString(),true);

        });
    }

    @Override
    protected void onObjectDataChange(JSONObject object) {
        super.onObjectDataChange(object);
        if (object.getIntValue("code")==0){
            startActivity(MainActivity.class);
            finish();
        }
    }
}
